package com.oa.modules.approvalsec1.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.oa.common.utils.AppUtils;
import com.oa.common.utils.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.oa.common.utils.PageUtils;
import com.oa.common.utils.Query;

import com.oa.modules.approvalsec1.dao.DataDocumentDao;
import com.oa.modules.approvalsec1.entity.DataDocumentEntity;
import com.oa.modules.approvalsec1.service.DataDocumentService;


@Service("dataDocumentService")
public class DataDocumentServiceImpl extends ServiceImpl<DataDocumentDao, DataDocumentEntity> implements DataDocumentService {
    @Autowired
    private DataDocumentDao dataDocumentDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        params.put("status", Constant.YES_OR_NO.YES.getValue());
        IPage page= AppUtils.getPage(new Query<DataDocumentEntity>(), params);
        return AppUtils.setPage(page, baseMapper.findPage(params), baseMapper.findRecords(page, params));
    }

    @Override
    public List<DataDocumentEntity> queryDataDocumentByName(Map<String, Object> params) {
        LambdaQueryWrapper<DataDocumentEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if(params.get("companyName") != null && !"".equals(params.get("companyName"))){
            lambdaQueryWrapper.eq(DataDocumentEntity::getCompanyName, params.get("companyName"));
        }
        if(params.get("topCategory") != null && !"".equals(params.get("topCategory"))){
            lambdaQueryWrapper .eq(DataDocumentEntity::getTopCategory, params.get("topCategory"));
        }
        List<DataDocumentEntity> list = dataDocumentDao.selectList(lambdaQueryWrapper);
        return list;
    }

    @Override
    public void updateType(HashMap<String, Object> params) {

        LambdaUpdateWrapper<DataDocumentEntity> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(DataDocumentEntity::getCompanyName,params.get("companyName"))
                .eq(DataDocumentEntity::getMatterName,params.get("matterName"));
        lambdaUpdateWrapper.set(DataDocumentEntity::getType,params.get("type"));
        dataDocumentDao.update(null,lambdaUpdateWrapper);
    }

}
